﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Strom.Core.Accounts;
using Strom.Server.IO;

namespace Strom.Server.Commands
{
    class CreateAccountCommand : BaseCommand, IConsoleCommand
    {
        public void ExecuteWithParameters(string[] parameters)
        {
            if (parameters.Length != 2)
            {
                InvalidParameters();
                return;
            }


                if (!ServerDatas.Server.Database.AccountsManager.AccountExists(parameters[0]))
                {
                    ServerDatas.Server.Database.AccountsList.Add(new Account(new AccountInfos(parameters[0], Core.Utils.Cryptography.ToMD5(parameters[1]))));
                    ServerConsole.WriteSpecialMessageCommand("\tLe compte " + parameters[0] + " a été créé.", ServerConsole.MessageType.Success);
                }
                else
                    ServerConsole.WriteSpecialMessageCommand("\tLe compte " + parameters[0] + " existe déjà.", ServerConsole.MessageType.Fail);
        }

        public static string CommandName
        {
            get { return "acc_create"; }
        }
    }
}
